﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lyh.Libs.Xml;
using System.Xml;
using Lyh.Dbdg.Model;
using Lyh.Dbdg.Business;

namespace Lyh.Dbdg.UI
{
    public class Context
    {
        private XmlHelper xml;

        public Context(string category)
        {
            var path = string.Format("{0}\\{1}\\properties.config", Environment.CurrentDirectory, category);
            xml = new XmlHelper(path);
        }

        private IDictionary<string, string> setting = new Dictionary<string, string>();
        public IDictionary<string, string> Setting
        {
            get
            {
                var nodes = xml.GetNodes("/settings/add");
                foreach (XmlNode node in nodes)
                {
                    setting.Add(node.Attributes["key"].Value, node.Attributes["value"].Value);
                }
                return setting;
            }
            set
            {
                var nodes = xml.GetNodes("/settings/add");
                foreach (XmlNode node in nodes)
                {
                    var v = node.Attributes["key"].Value;
                    if (value.ContainsKey(v))
                    {
                        node.Attributes["value"].Value = value[v];
                    }
                }
                xml.Save();
            }
        }
    }
}